<html xmlns:th="http://www.thymeleaf.org">
<head th:include="layout :: htmlhead" th:with="title='按报告期'"></head>

<body>
<div class="container">
    <h4 class="float-left mt-2">按报告期：</h4>
    <div class="form-horizontal">
        <input type="hidden" name="shareId" th:value="${shareId}"/>
        <div class="form-group">
            <div id="inner">
                <div class="ext">
                    <label for="revenueReportDate" class="col-sm-2 control-label">日期:</label>
                    <div class="col-sm-10">
                        <input id="revenueReportDate" class="form-control" placeholder="日期" type="date" th:name="revenueReportDate">
                    </div>
                    <label for="revenueReport" class="col-sm-2 control-label">营业总收入:</label>
                    <div class="col-sm-10">
                        <input id="revenueReport" class="form-control" placeholder="营业总收入" type="text" th:name="revenueReport">
                    </div>
                </div>
            </div>

            <div class="col-sm-offset-2 col-sm-10">
                <button type="submit" class="btn btn-default" id="addDate">增加日期</button>
                <button type="submit" class="btn btn-default" id="minusDate">减少日期</button>
                <button type="submit" class="btn btn-default" id="create">提交</button>
            </div>
        </div>
    </div>
</div>
<script>
    jQuery(document).ready(function(){
        var data = $("#inner").html();
        $("#addDate").click(function() {
            $("#inner").append(data);
            if (!$("#create").is(":visible")) {
                $("#create").show();
            }
        })
        $("#minusDate").click(function() {
            $(".ext:last").remove();
            if ($(".ext").length === 0) {
                $("#create").hide();
            }
        })
        $("#create").on("click", function(){
            var sendData = {};
//            var obj = {"revenueReportModels":[{"revenueReportDate":"2019-08-21", "revenueReport": "11"},{"revenueReportDate":"2019-08-21", "revenueReport": "11"}]};
            var obj = [];

            var revenueReportModels = {};
            revenueReportModels["revenueReportDate"] = $("#revenueReportDate9").val();
            revenueReportModels["revenueReport"] = $("#revenueReport9").val();
            obj.push(revenueReportModels);

            sendData['revenueReportModels'] = obj;

            var result = JSON.stringify(sendData);

            console.log(result);

            var object = {};
            var params = [];

            for(var i = 0; i < 3; i++){
                var obj = {};
                obj[i] = "abc";
                params.push(obj);

            }
//            object['name'] = 'jack';
//            object['age'] = 25;
            object['data'] = params;

            var json = JSON.stringify(object);
            console.log(json);

            $.ajax({
                type: "POST",
                contentType: "application/json",
                url:"http://localhost:8081/revenueReport/saveInfo",
                data:result,
                success:function(data) {
                    alert(data);
                }
            })
            return false;
        });
    });
</script>
</body>


</html>